package com.china08.yxyapi.api.home.kecheng.topic;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.YxyLessonsTopicLesson;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyLessonsTopicLessonRepository;

/**
 * 专题课程--判断用户是否vip会员/课程是否vip课程
 * 
 * @author LiuWeidong
 *
 */
@CrossOrigin
@RestController
public class KechengTopicUserIfVipController extends YxyApiBaseController {

    // @Autowired
    // private UserVipValidateServiceImpl userVipValidateServiceImpl;

    @Autowired
    private YxyLessonsTopicLessonRepository yxyLessonsTopicLessonRepository;

    @RequestMapping(value = "/api_yw/home/kecheng/topic/vip1/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel find(HttpServletRequest request,
            HttpServletResponse response, @RequestBody ReqModel reqModel) {

        String lessonId = reqModel.lessonId;
        // String userId = getProfile(request, response).getId();
        // String schoolId = getProfile(request, response).getSchoolId();
        // String functionId = "yx_0006";

        RespModel respModel = new RespModel();
        // respModel.vip = userVipValidateServiceImpl.userVipValidate(userId,
        // schoolId, functionId);

        String vipString = getProfile(request, response).getUserVip();
        String gerenVip = getProfile(request, response).getPerVip();
        Boolean userVip;
        if (vipString.equals("true") || gerenVip.equals("true")) {
            userVip = true;
        } else {
            userVip = false;
        }

        respModel.vip = userVip;

        YxyLessonsTopicLesson synchroLessons = yxyLessonsTopicLessonRepository
                .findById(lessonId);
        respModel.keChengVip = synchroLessons.getVip();
        respModel.epTimes = synchroLessons.getEpTimes();
        return respModel;
    }

    /* 请求参数 */
    protected static class ReqModel extends YxyApiPageReqModel {
        // 课程ID
        public String lessonId;
    }

    /* 响应参数 */
    protected static class RespModel extends YxyApiRespModel {
        public Boolean vip;// 是否为vip

        // 课程是否vip 0--非vip 1--vip课程
        public Integer keChengVip;

        // 评价人数
        public Integer epTimes;
    }

}
